package com.smart.controller.app;

import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.util.ArrayList;
import com.smart.util.DateUtil;
import com.smart.util.Messages;
import javax.annotation.Resource;
import io.swagger.annotations.Api;
import com.smart.req.InspectionParam;
import com.smart.entity.SysDictDetail;
import io.swagger.annotations.ApiOperation;
import com.smart.controller.BaseController;
import com.smart.entity.SysInspectionRecord;
import com.smart.service.SysDictDetailService;
import com.smart.service.InspectionRecordService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lgb
 * @date 2020年6月10日 上午7:55:33
 * Copyright (C) 深圳工勘科技
 * @说明: 设备管理
 **/
@RestController
@RequestMapping("/app/inspect")
@Api(value="app",tags="设备巡查管理")
public class InspectionRecordController extends BaseController{

	@Resource
	private InspectionRecordService inspectionRecordService;
	@Resource
    private SysDictDetailService sysDictDetailService;
	@ApiOperation(value="app=>新增巡查",notes="app=>新增巡查")
	@PostMapping(value="/add")
	public Messages<String> save(@RequestBody InspectionParam param){
		int res = inspectionRecordService.save(param);
		if(res==1){
			return Messages.success(DateUtil.formatCurrentDateToLongStr());
		}
		return Messages.failed("录入失败!");
	}
	
	@GetMapping(value="/page")
	@ApiOperation(value="app=>获取巡查历史列表",notes="app获取巡查记录列表")
	public Messages<List<SysInspectionRecord>> page(String createTime,
			@RequestParam(name="pageNum")Integer pageNum,
			@RequestParam(name="pageSize")Integer pageSize){
		IPage<SysInspectionRecord> page=
				inspectionRecordService.findPage(pageNum,pageSize,createTime);
	    return Messages.success(page.getRecords());
	}
	
	@ApiOperation(value="app获取巡查项目树",notes="app获取巡查项目树")
	@GetMapping(value="/tree")
	public Messages<Object> tree(){
		List<SysDictDetail> list =
				sysDictDetailService.selectDictDataByType("car_inspection_pro");
		List<Map<String,Object>> data = new ArrayList<>();
		if(!list.isEmpty()){
			for(SysDictDetail dict : list){
				Map<String,Object> map = new HashMap<>();
				map.put("id", dict.getId());
				map.put("name", dict.getDictLabel());
				data.add(map);
			}
		}
		return Messages.success(data);
	}
	
	
}